package com.qfedu.meidijiaju.controller;

import com.qfedu.meidijiaju.entity.Like;
import com.qfedu.meidijiaju.common.ResponseData;
import com.qfedu.meidijiaju.service.LikeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "我的收藏模块接口")
@RestController
public class LikeController {

    @Autowired
    private LikeService likeService;

    @ApiOperation("查询当前用户的收藏列表，需要前端传递uid")
    @RequestMapping(value = "/like/queryLikeInfo",method = RequestMethod.GET)
    public ResponseData<List<Like>> queryLikeInfo(int uid) {
        ResponseData<List<Like>> responseData = new ResponseData<>();
        List<Like> result = likeService.queryLikeInfo(uid);

        if (result != null) {
            responseData.setCode(0);
            responseData.setData(result);
        }

        return responseData;
    }

    @ApiOperation("添加收藏")
    @RequestMapping(value = "/like/addLike",method = RequestMethod.GET)
    public ResponseData<String> addLike(Like like) {
        ResponseData<String> responseData = new ResponseData<>();
        boolean result = likeService.addLike(like);

        if (result) {
            responseData.setCode(0);
            responseData.setMsg("添加收藏成功");
        }

        return responseData;
    }

    @ApiOperation("取消收藏，需要传递挡墙用户uid、文章创建人createUid、文章名name")
    @RequestMapping(value = "/like/deleteLike",method = RequestMethod.GET)
    public ResponseData<String> deleteLike(Like like) {
        ResponseData<String> responseData = new ResponseData<>();
        boolean result = likeService.deleteLike(like);

        if (result) {
            responseData.setCode(0);
            responseData.setMsg("取消收藏成功");
        }

        return responseData;
    }
}
